////////////////////////////////////////////////////////////////////
// File:				Batch.h
// Author(s):			Gerald Leung (GL), Jeremy Cowles (JC)
// Creation Date:		Sat Feb 06 03:35:00 PST 2008
// Spec:				
// Purpose:				Batch Classes Implementation
////////////////////////////////////////////////////////////////////

// Implementation-dependent Includes
// Interface Includes
#include	"BatchViewController.h"

			BatchViewController::BatchViewController(void)
{
	_pCurrentBatch	= NULL;
	_nWorkUnits		= 0;
	_nWidth			= 0;
	_nDepth			= 0;
	_nHeight		= 0;
	_nFootprint		= 0;
	_nTopFloor		= 0;
	_fInvScale		= 0.0f;
}

			BatchViewController::~BatchViewController(void)
{
	_pCurrentBatch	= NULL;
}

void		BatchViewController::draw()
{
	//glColor3f			(0.8, 0.1, 0.2);
	//glBegin				(GL_QUADS);
	//	glNormal3f		(0.000,  0.000,  1.000);
	//	glVertex3f		(1.400,  0.000,  2.400);
	//	glVertex3f		(1.400, -0.784,  2.400);
	//	glVertex3f		(0.784, -1.400,  2.400);
	//	glVertex3f		(0.000, -1.400,  2.400);
	//glEnd				();
	//glColor3f		(0.35, 0.35, 0.4);
	if (_nWorkUnits > 0)
	{
		glColor3f		(0.35, 0.35, 0.4);
		glLineWidth		(1);
		glBegin			(GL_LINES);
		for (unsigned x = 0; x <= _nWidth; x++)
		{	
			// x lines
			glVertex3f(x, 0, 0);	glVertex3f(x, 0, _nDepth);
			glVertex3f(x, 0, 0);	glVertex3f(x, _nHeight, 0);
			glVertex3f(x, _nHeight, 0);	glVertex3f(x, _nHeight, _nDepth);
			glVertex3f(x, 0, _nDepth);	glVertex3f(x, _nHeight, _nDepth);
		}
		for (unsigned y = 0; y <= _nHeight; y++)
		{	
			// y lines
			glVertex3f(0, y, 0);	glVertex3f(0, y, _nDepth);
			glVertex3f(0, y, 0);	glVertex3f(_nWidth, y, 0);
			glVertex3f(_nWidth, y, 0);	glVertex3f(_nWidth, y, _nDepth);
			glVertex3f(0, y, _nDepth);	glVertex3f(_nWidth, y, _nDepth);
		}
		for (unsigned z = 0; z <= _nDepth; z++)
		{	
			// z lines
			glVertex3f(0, 0, z);	glVertex3f(0, _nHeight, z);
			glVertex3f(0, 0, z); 	glVertex3f(_nWidth, 0, z);
			glVertex3f(0, _nHeight, z);	glVertex3f(_nWidth, _nHeight, z);
			glVertex3f(_nWidth, 0, z);	glVertex3f(_nWidth, _nHeight, z);
		}
		glEnd();
	}
}

void		BatchViewController::setCurrentBatch(Batch *pNewBatch)
{
	// Compute display parameters
	_pCurrentBatch	= pNewBatch;
	_nWorkUnits		= _pCurrentBatch->getNumWorkUnits();
	_nWidth			= 5;
	_nDepth			= 5;
	_fInvScale		= 2.0f/(_nWidth, _nDepth, _nWidth);

	// Footprint of floors that are Width * Depth large
	_nFootprint		= _nWidth * _nDepth;

	// Height of the building
	_nHeight		= _nWorkUnits / _nFootprint;

	// Leftovers for the top floor
	_nTopFloor		= _nWorkUnits % _nFootprint;
}
